L1-033 出生年

题目 L1-033 出生年

image-f5e74bbb

思路分析

代码实现

#include<bits/stdc++.h>

using namespace std;

#define endl '\n'

#define int long long

using ll = long long;

using ull = unsigned long long;

using PII=pair<int,int>;

using Pll = pair<ll,ll>;

int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};

const int inf = 0x3f3f3f3f;

signed main()

{

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	int y,n;cin>>y>>n;

	int cnt=0;

	for(int i=y;;i++){

		int temp=i;

		set<int> havenum;

		cnt++;

//		while(temp){ //无法处理 000?年的逻辑

//			havenum.insert(temp%10);

//			temp/=10;

//		}

		for(int i=0;i<4;i++){

			havenum.insert(temp%10);

			temp/=10;

		}

		if(havenum.size()==n){

			printf("%d %04d",cnt-1,i);

			break;

		}

	}

	return 0;

 }

同类题型

视频讲解


⬅️ L1-032 Left-pad 🏠 00-天梯赛 ➡️ L1-034 点赞